﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="FL.Web.BackEnd.DataGrid" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style>
        html, body {
            margin: 0;
            padding: 0;
            border: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
        .col1 {
            float: left;
            width: 20%;
        }

        .col2 {
            float: left;
            width: 40%;
        }

        .query_table {
            width: 100%;
        }

        .label {
            width: 90px;
            text-align: right;
        }

        .exp {
            width: 60px;
        }

        .exp > select {
            width: 60px;
        }
    </style>
</head>
<script src="../../SFramework/boot.js"></script>
<script src="../../SFramework/linq.js"></script>
<script src="../../SFramework/linq.min.js"></script>
<script> var currentUser = <%=FL.Common.Globals.ObjectToJSON(User)%>;//当前登录人员工id
</script>
<body style="margin: 0px; padding: 0px">

    <div class="mini-toolbar" style="border-bottom: 0; padding: 2px;">
        <table style="width: 100%;">
            <tr>
                <td style="width: 100%;" id="tool_button_bar">
                    <div id="button_bar">
                        <a class="mini-button"  iconcls="icon-add" plain="true"  onclick="fnMoveUp()" id="btnMoveUp" place="">上移</a>
                        <a class="mini-button"  iconcls="icon-edit" plain="true"  onclick="fnMoveDown()" id="btnMoveDown" place="">下移</a>
                        <a class="mini-button"  iconcls="icon-edit" plain="true"  onclick="fnDeleteSetting()" id="btnDeleteSetting" place="">取消设置</a>
                        <a class="mini-button"  iconcls="icon-add" plain="true"  onclick="fnSave()" id="btnSave" place="">保存</a>
                    </div>
                </td>
                
            </tr>
        </table>
        
    </div>
    <div class="mini-fit">
        <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 100%;" pagesize="<% =GetStringFromQueryString("pagesize","100") %>" allowresize="true" allowscroll="true" allowcelledit="true" allowcellselect="true" multiselect="true"
            editnextonenterkey="true" editnextrowcell="true"  multiselect="<%=GetStringFromQueryString("selectMode","true")%>" url="../data/jsondata.aspx?nodataright=true&functionid=<%=GetStringFromQueryString("functionid","") %>&entity=<%=EntityName%>&condition=<%=Condition %>&order=sort&desc=No&datagrid=true&totalfields=<%=GetStringFromQueryString("totalfields","")%>&r=1" pagesize="500" >
            <div property="columns">
                <div type="indexcolumn" width="30"></div>
                <div field="caption"  name="caption" width="80" headerAlign="center"   renderer="" >表头名称</div>
                <div field="width"  name="width" width="50"  headerAlign="center"   renderer="">宽度<input property="editor" class="mini-textbox" style="width:100%;"    renderer=""/></div>
                <div field="sort"  name="sort" width="20"  headerAlign="center"  renderer="">排序<input property="editor" class="mini-textbox" style="width:100%;"    renderer=""/></div>
                <div field="is_visiable"  name="is_visiable" width="50"  headerAlign="center"   renderer=""  type="comboboxcolumn">是否可视 <input property="editor" class="mini-combobox" style="width:100%;" data="is_YN_data"/></div>
            </div>
        </div>
    </div>
    <form id="form1" class="mini-menu" style="display: none;">
        <input id="datagrid_data"/>
    </form>

</body>
<script type="text/javascript">
    var  const_action = "",
    const_entityID = "<% =EntityId %>",    //实体ID名称
    const_entityName = "<% =EntityName %>",//实体名称
    const_EditEntity = "<% =EditEntity %>",//编辑实体名
    const_ViewEntity = "<% =this.GetStringFromQueryString("View_Entity","")%>",
    const_functionId   ="<% =FunctionID %>",//自定义条件
    const_Order ="<% =Order %>",           //排序  
    const_UserId = "<% = UserId %>",       // 
    const_TreeCustomCondition = "";        //主从关系条件 
    const_QueryField="<% =QuciklyQueryFields %>",
    const_CustomCondition = encodeURI("<% =DefineCondition %>"),//查询方案条件
    const_Condition = encodeURI("<% =Condition %>"),//
    const_TreeCustomCondition = "";
    const_PageTitle=encodeURI("<% =PageTitle %>"),
    _openWindowHeight=<%=EditWindowHeight%>,
    _openWindowWidth=<%=EditWindowWidth%>,
    _mergeCols = "<%=GetStringFromQueryString("mergeCols","") %>",
    _noNeedLoadData="<%=GetStringFromQueryString("noNeedLoadData","0")%>";
    <% =ColumnDataSource%>
    var is_YN_data=[{"text":"是","id":"Y"},{"text":"否","id":"N"}];
</script>

<script type="text/javascript">

    var instance = { id: "", function_id: const_functionId, datagrid_data: "",add_user:"",add_time:""};
    var grid = null;
    // $("#datagrid1").height($(document).height() - (35+2));
    $(document).ready(function(){

        if($(".mini-toolbar").height()>37&&const_entityName!="v_t_mains")
        {
            $("#button_bar").hide();
            $('<a class="mini-menubutton" plain="true" menu="#popupMenu" style="width:60px">按钮</a>').insertBefore("#button_bar");
        } 
        else{
            $("#button_bar").removeClass();
            $("#button_bar").show();
        }
        mini.parse();
        grid= mini.get("datagrid1")
        // var mergeCols = getPar("mergeCols");
        if(_mergeCols!="")
        {
            grid.on("load", function () {
                grid.mergeColumns(_mergeCols.split(","));
            });
        }
        else{
            if(_noNeedLoadData=="0")
            {
                grid.load();
            }
        }
        //if(const_QueryFieldsText!="")
        //{
        //    initQuerySelect();
        //}

    });

    function initQuerySelect()
    {
        var texts = const_QueryFieldsText.split(",")
        var fields = const_QueryField.split(",");
        var strSelectHtml = "<select id='QuerySelectItem' style='width:40px;'><option value=''></option>";
        for(var i=0;i<texts.length;i++)
        {
            strSelectHtml = strSelectHtml+"<option value='"+fields[i]+"'>"+texts[i]+"</option>"
        }
        strSelectHtml=strSelectHtml+"</select>";
        $("#selQueryItem").html(strSelectHtml);//.insertBefore($("#QueryContext"));
    }

    function getData()
    {
        return grid.data;
    }

    var columns;
    function setData(cols)
    {
        //alert(cols);
        columns =cols;
        setTimeout(function(){
            $.each(grid.data,function(index,item){
                //if(e.field==item.field_name)
                //{
                    item.sort=index;
                    var row=grid.getRow(index);
                    grid.updateRow ( row, item );
                //}
            });
            for(var i=0; i<columns.length;i++)
            {
                for(var index=0;i<grid.data.length;index++)
                {
                    if(columns[i].field==grid.data[index].field_name){
                        grid.data[index].sort=i;
                        var row=grid.getRow(index);
                        grid.updateRow(row, grid.data[index]);
                        //grid.moveRow(row, i);
                        break;
                    }
                }
            }

        },6000);

        //if()
    }
    
    function fnSave() {
        //alert(grid.data);
        $("#datagrid_data").val(mini.encode(grid.data));
        instance.datagrid_data=mini.encode(grid.data);
        ///数据检查
        if (typeof (fnCustomDataCheck) != "undefined") {
            var msg = fnCustomDataCheck();
            if (msg != "") {
                alert(msg);
                return;
            }
        }
        ///客制化数据保存
        if (typeof (fnCustomSave) != "undefined") {
            fnCustomSave();
            return;
        }

        //var form = new mini.Form("#form1");
        //form.validate();
        //if (!form.isValid()) return;
        //var form_data = form.getData();
        //fnClone(form_data, instance);
        if (typeof (instance) != "undefined" && instance != null) {
            var msg = mini.loading("数据保存中，请稍后......", "系统消息提醒");
            var json = mini.encode(instance);   //序列化成JSON
            $.ajax({
                url: "/extendpage/action/datasave.aspx?entity=t_sys_user_datagrid_config&flag=1&action=insert",
                type: "post",
                data: { data: json },
                cache: false,
                success: function (text) {
                    if (text == 1) {
                        mini.alert("数据保存成功!")
                        fnClose();
                    } else {
                        mini.alert(text);
                        //alert("数据保存失败!")
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                }
            });
            mini.hideMessageBox(msg);
        }
    }

    ///克隆对象
    var fnClone2 = function (sourceObject, targetObject) {
        $.each(sourceObject, function (property, value) {
            if (property != "") {
                var _value = value;
                if (_value != null && _value != "") {
                    if (_value.toString().indexOf("GMT") > 0) {
                        _value = mini.formatDate(_value, "yyyy-MM-dd H:mm:ss");
                    }
                }
                targetObject[property] = $.trim(_value);

                //eval("targetObject." + property + "='" + value + "'");
            }
        });
    };

    ///克隆对象
    var fnClone = function (sourceObject, targetObject) {
        $.each(sourceObject, function (property, value) {
            if (property != "") {
                var _value = value;
                if (_value != null && _value != "") {
                    if (_value.toString().indexOf("GMT") > 0) {
                        _value = mini.formatDate(_value, "yyyy-MM-dd H:mm:ss");
                    }
                    if (_value.toString().indexOf("1900-01-01") > -1) {
                        _value = null;
                    }
                }
                if (_value == null) {
                    targetObject[property] = null;
                } else {
                    targetObject[property] = $.trim(_value);
                }
            }
        });
    };
     

/**********************************
*上移
**************************************/
    function fnMoveUp() {
        var row = grid.getSelected();
        if (row) {
            //当前行下标
            var index = grid.indexOf(row);
            if (index>0) {
                /*******add by zengtongchun 2015-07-01 begin*********/
                //上一条的行对象
                var row1 = grid.getRow(index - 1);
                grid.updateRow(row, { sort: row.sort - 1 });//当前序号-1
                grid.updateRow(row1, { sort: row.sort + 1 });//上一条序号+1
                /*******add by zengtongchun 2015-07-01 end*********/
                grid.moveRow(row, index - 1);
            }

        }

    }

    /**********************************
    *下移
    **************************************/
    function fnMoveDown() {
        var row = grid.getSelected();
        if (row) {
            //当前行下标
            var index = grid.indexOf(row);
            if (index<grid.data.length-1) {
                /*******add by zengtongchun 2015-07-01 begin*********/
                //上一条的行对象
                var row1 = grid.getRow(index + 1);
                grid.updateRow(row, { sort: parseInt(row.sort) + 1 });//当前序号+1
                grid.updateRow(row1, { sort: parseInt(row.sort) - 1 });//上一条序号-1
                /*******add by zengtongchun 2015-07-01 end*********/
                grid.moveRow(row, index + 2);
            }

        }
    }


    //var frozen =getPar("frozen");
    //if(frozen!="")
    //{
    //    eval("grid.frozenColumns ("+frozen+")");
    //}
    //$("input[id^='code']");//id属性以code开始的所有input标签 
    //$("input[id$='code']");//id属性以code结束的所有input标签 
    //$("input[id*='code']");//id属性包含code的所有input标签 
    //grid.frozenColumns (3,4);

</script>
<script src="../../Scripts/datagrid/list.common.button.js"></script>
<script src="../../Scripts/common/jquery.action.js"></script>
<script src="../../Scripts/common/jquery.data.js"></script>
<script>

</script>
<script>
    //
    // 
    //
    var config_data = null;
    function LoadData()
    {
        var _data = fnGetSingleData("t_sys_user_datagrid_config","add_user='@UserID' and function_id='<%=this.FunctionID%>'");
        if(_data!=null)
        {
            var data = eval("("+_data[0].datagrid_data+")");
            grid.setData(data);
        }
        config_data = data;
    }

    
    function fnDeleteSetting(){
        $.ajax({
            url: "/extendpage/action/datasave.aspx?function_id='<%=this.FunctionID%>'&entity=t_sys_user_datagrid_config&action=delete&id=" + config_data.id,
            success: function (text) {
                if (text == 1) {
                    alert("删除成功!");
                }
                grid.reload();
            },
            error: function () {
            }
        });
    }

    $(document).ready(function(){
        setTimeout(LoadData,1000);
    })
    //var __data=localStorage.getItem("test");
    //if(__data==null){
    //    localStorage.setItem("test",Date.now);
    //}
    //else
    //{
    //    alert(__data);
    //}
</script>
<script src="../../Scripts/hotkey.js"></script>
<script src="../../Scripts/common/juqery.Keyborad.js"></script>
</html>
